local player = Var "Player"
local blinkTime = 1.2

local t = Def.ActorFrame{
	Def.Sprite{
		-- xxx: assumes course is 4lives
		InitCommand=function(self)
			if GetScreenAspectRatio() >= 1.7777777777777777777777777777778 then
				self:Load(THEME:GetPathG("LifeMeterBattery","lives/_lives_sixteennine"));
			elseif GetScreenAspectRatio() >= 1.6 then
				self:Load(THEME:GetPathG("LifeMeterBattery","lives/_lives_sixteenten"));
			else
				self:Load(THEME:GetPathG("LifeMeterBattery","lives/_lives_threefour"));
			end;
			self:pause();
			self:zoomtowidth(SCREEN_WIDTH/2-60);
			self:setstate(3);
		end;
		LifeChangedMessageCommand=function(self,param)
                        if param.Player == player then
                                if param.LivesLeft == 0 then
					self:diffusealpha(1);
                                        self:linear(0.2);
					self:diffusealpha(0);
                                elseif param.LivesLeft <= 4 then
					self:diffusealpha(1);
                                        self:setstate( math.max(param.LivesLeft-1,0) )
                                else
					self:diffusealpha(1);
                                        self:setstate(3);
                                end
                        end
                end;
        };
	
	LoadActor("failed")..{
		InitCommand=cmd(zoomy,0;y,206);
		LifeChangedMessageCommand=function(self,param)
			if param.Player == player then
				if player == PLAYER_2 then
					self:rotationy(180);
				else
					self:zoomx(1);
				end;
				if param.LivesLeft == 0 then
					self:visible(true);
					self:zoomy(0);
					if player == PLAYER_2 then
						self:sleep(0.5);
						self:glow(color("0,0,0,0"));
						self:addx(-300);
						self:linear(0.1);
						self:addx(300);
						self:zoomy(1);
						self:glow(color("1,0,0,1"));
						self:linear(0.2);
						self:glow(color("0,0,0,0"));
					else
						self:sleep(0.5);
						self:glow(color("0,0,0,0"));
						self:addx(-300);
						self:linear(0.1);
						self:addx(300);
						self:zoomy(1);
						self:glow(color("1,0,0,1"));
						self:linear(0.2);
						self:glow(color("0,0,0,0"));
					end;
				else
					self:visible(false);
					self:zoomy(0);
				end
			end
		end;
	};
};

return t;